<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>

<link href="../../css/v4/common/base.css" type="text/css" rel="stylesheet" />
<link href="/css/v4/common/hf.css" type="text/css" rel="stylesheet" />
<link href="/css/v4/channel.css" type="text/css" rel="stylesheet" />

<script src="/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/js/jquery.json-2.2.min.js" type="text/javascript"></script>
<script src="/js/jquery.form.js" type="text/javascript"></script>
<script src="/js/v3/jquery.com.js" type="text/javascript"></script>
<script src="/js/v3/com.plugin.js" type="text/javascript"></script>
<!--[if ie 6]><script src="../../js/v4/iepng.js" type="text/javascript"></script><![endif]-->
<!--[if ie]><link href="../../css/v4/common/IE.css" type="text/css" rel="stylesheet"><![endif]-->
<script type="text/javascript">
	$(function() {

		$.fn.popDiv({tcID : "share_xinde", opacity : 0.4, isZZ : true, speed : 0, noResize : true ,moveTC:function(){
			$("#back_share_product").remove();
		}});
		
	});
	//分享商品产生微博
	function shareproduct(){
		$.post("/getsonid.htm",function(memberId){
			var share = $("#textarea_share").val();
			if(share.length > 140){
				alert("最多可以输入140个字，您输入的太多了");
				return ;
			}else{
				$("#share_xinde_button").unbind("click");
				var productList = new Array();
				product.name = product.title;
				product.originalId = product.numIid;
				product.maxPrice = product.price;
				product.sellerNick = product.nick;
				product.picUrl = $("#share_xinde_imgs").find("li:visible:first").find("img:first").attr("src");
				product.linkUrl = "http://item.taobao.com/item.htm?id="+product.numIid;
				product.from = "淘宝";
				product.status = "onsale";
				productList.push(product);
				$.post("/shareproduct.htm", {
					'memberId' : memberId,
					'content' : share,
					'productList' : escape($.toJSON(productList))
				}, function(data) {
					if(data.msg == "success"){
						alert("分享成功");
						$("#back_share_product").remove();
					}else{
						alert("亲，系统抽经了，请稍候重试");
					}
				}, "json");
			}		
		});
	}

	//输入字数
	function remain(textarea, remain, max){
		$("#" + remain).show();
		var content = $("#" + textarea).val();
		//取得用户输入的字符长度
		var length = content.length;
		if (length <= max) {
			$("#" + remain)
					.html("<i>" + (max - length)
									+ "</i>/"+140);
			return true;
		} else {
			$("#" + remain).html(
					"&nbsp;超出 <font size='3'color='red' id='remain'>" + (length - max)
							+ "</font> 字");
			return false;
		}
	}
	
	//上传本地图片
	function uploadFileChange(self){
		var filepath = $(self).val();
		var extStart = filepath.lastIndexOf(".");
		var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		if (ext != ".PNG" && ext != ".JPG" && ext != ".JPEG" && ext != ".GIF") {
			alert("图片限于png,jpeg,jpg,gif格式");
			return;
		}
		$(self).parent().ajaxSubmit({
			dataType : 'json',
			cache : false,
			success : function(data) {
				var ul = $("#share_xinde_imgs");
				var liSize = ul.find("li").size();
				$(ul).find("li").hide();
				if(liSize > 1){
					ul.append('<li style="display:block;" value="'+liSize+'"><img src="'+data.imageServer+data.pictureUrl+'" class="block" width="182" height="182"/></li>');
				}else{
					$("#share_xinde_pic").attr("src",data.imageServer+data.pictureUrl);
				}
			},
			error : function(err) {
				alert(err);
			}
		});
		return false;
	}
	
	//浏览图片列表
	function browsePic(self) {
		var text = $(self).text();
		var ul = $(self).parent().parent().find("ul:first");
		var li = $(ul).find("li:visible:first");
		var liNo = $(li).attr("value");
		var liSize = ul.find("li").size();
		$(ul).find("li").hide();
		if (text == "下一张>") {
			//如果已经到了最后一张
			if ((liNo + 1) == liSize) {
				$(ul).find("li:first").show();
			} else {
				$(ul).find("li::eq(" + (liNo + 1) + ")").show();
			}
		} else {
			//如果是第一张
			if (liNo == 0) {
				$(ul).find("li::eq(" + (liSize - 1) + ")").show();
			} else {
				$(ul).find("li::eq(" + (liNo - 1) + ")").show();
			}
		}
	}
</script>
<%-- 分享心得弹出框 --%>
<div class="tc_box release_box" id="share_xinde">
	<div class="release_title">
		<a href="javascript:void(0);" class="tc_close close_btn">关闭</a>
		<p>分享一件商品给更多妈妈</p>
	</div>
	<div class="content clearfix">
		<div class="rel_box2">
			<div class="rel_pic_box">
				<div class="rel_pic_head clearfix"><a href="javascript:void(0);" onclick="$('#uploadFile').click()">本地图片</a>商品图片</div>
				<form enctype="multipart/form-data"
					method="post" action="/misc/cms/backgroundImgUpload.htm"
					style="display: block;">
				<input type="file" name="img" id="uploadFile" onchange="uploadFileChange(this)" style="display: none;"/>
				<input type="hidden" name="contentId" value="temp">
				</form>
				<ul class="rel_pic_det" id="share_xinde_imgs">
					<li><img src="" class="block" width="182" height="182" id="share_xinde_pic" /></li>
				</ul>
				<div class="rel_fy clearfix" id="share_xinde_next">
					<a href="javascript:void(0);" onclick="browsePic(this)"
						class="fr mr10">下一张&gt;</a><a href="javascript:void(0);"
						onclick="browsePic(this)" class="fl ml5">&lt;上一张</a>
				</div>
			</div>
		</div>
		<div class="rel_box1">
			<div class="rel_pro_det">
				<a class="title" id="share_xinde_title"></a>
				<span id="share_xinde_price" class="price"></span>
				<div class="write_box">
					<textarea autocomplete="off" onkeyup="remain('textarea_share','doing_content_error',140)" onkeydown="remain('textarea_share','doing_content_error',140)" id="textarea_share"></textarea>
					<div class="face_box">
						<span class="fr mr10" id="doing_content_error"><i>0</i>/140</span>
						<a href="javascript:void(0);" class="face_link"><img src="../../images/v4/other/icon_5.png" />表情</a>
					</div>
				</div>
				<div class="clear"></div>
				<div>
					<input type="button" value="分 享" id="share_xinde_button" onclick="shareproduct()" class="def_btn_s2">
				</div>
			</div>
		</div>

	</div>
</div>

<div class="zz_box"></div>